package com.t.bricks.bussiness.service.roleandright.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.t.bricks.bussiness.db.dao.roleandright.RoleAndRightDao;
import com.t.bricks.bussiness.service.roleandright.RoleAndRightService;
import com.t.bricks.model.MsgEmity;
import com.t.bricks.utils.spring.ModuleUtil;

/**
 * 角色权限表'RoleAndRight表'基本业务操作类接口实现
 */
@Service
public class RoleAndRightServiceImpl implements RoleAndRightService {

	@Autowired
	private RoleAndRightDao roleAndRightDao;
	
	/**
	 * 批量添加权限信息
	 * @param sRoleId
	 * @param sRightList
	 * @return
	 */
	@Override
	public MsgEmity add(String sRoleId, String sRightList) {
		if (null == sRoleId || "".equals(sRoleId.trim())) {
			return new MsgEmity(false, "角色编号不能为空！", 8001);
		}
		
		String currentLoginUserId = ModuleUtil.currentLoginUserId();//取当前登录用户编号
		return roleAndRightDao.add(sRoleId, sRightList, currentLoginUserId);
		//--下面的换用AOP来执行--//
//		MsgEmity me = roleAndRightDao.add(sRoleId, sRightList, currentLoginUserId);
//		if (me.isSuccess()) {
//			ModuleUtil.callServiceMethod("userAndRightServiceImpl", "clearCache", "");//删除缓存指定用户权限集合，因为角色的权限已经改变，对应的用户权限也会改变，必须进行缓存重构
//		}
//		
//		return me;
	}
	
	/**
	 * 根据角色编号取与权限关联的信息
	 * @param sRoleId 角色编号
	 * @return
	 */
	@Override
	public MsgEmity findByRoleId(String sRoleId) {
		if (null == sRoleId || "".equals(sRoleId.trim())) {
			return new MsgEmity(false, "编号不能为空！", 8001);
		}
		
		return roleAndRightDao.findByRoleId(sRoleId);
	}
	
}
